package com.ghck.server.service.impl;
import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ghck.server.dao.AnswerShareMapper;
import com.ghck.server.model.AnswerShare;
import com.ghck.server.model.query.AnswerShareQuery;
import com.ghck.server.service.AnswerShareService;

/**
 * 测试分享  <br>
 * t_answer_share <br>
 * v1.0 2016-05-01
 */
 @Service
 @Transactional
 public class AnswerShareServiceImpl implements AnswerShareService {
	
	private static final Logger logger = LoggerFactory.getLogger(AnswerShareServiceImpl.class);
	
	@Autowired
	private AnswerShareMapper answerShareMapper;
	
	/**
 	*根据ID删除 测试分享
 	*/
 	@Override
 	public Integer deleteAnswerShareById(Integer id){
 		return answerShareMapper.deleteById(id);
 	}
 	
 	/**
 	*新增 测试分享
 	*/
 	@Override
 	@Transactional
 	public Integer batchInsertAnswerShare(List<? extends AnswerShare> answerShares){
		Integer count = answerShareMapper.batchInsert(answerShares);
		return count;
 	}
 	/**
 	*新增 测试分享
 	*/
 	@Override
 	@Transactional
 	public Integer insertAnswerShare(AnswerShare domain){
		Integer id = answerShareMapper.insert(domain);
		return id;
 	}

 	/**
 	*更新 测试分享
 	*/
 	@Override
 	@Transactional
 	public Integer updateAnswerShare(AnswerShare domain){
		Integer count = answerShareMapper.update(domain);
		return count;
 	}
 	
 	/**
 	*根据ID查询 测试分享
 	*/
 	public AnswerShare findAnswerShareById(Integer id){
 		AnswerShare result = answerShareMapper.findById(id);
 		if(result!=null){
 			result.dealWith();
 		}
 		return result;
 	}

	/**
 	*通过query 查询 测试分享
 	*/
	public List<AnswerShare> findAnswerShareByQuery(AnswerShareQuery query){
		query.dealWith();
		List<AnswerShare> result = answerShareMapper.findByQuery(query);
		if(CollectionUtils.isNotEmpty(result)) {
			for (AnswerShare answerShare : result) {
				answerShare.dealWith();
			}
		}
		return result;
	}	
	
	/**
 	*通过query count总条数
 	*/
 	public Integer countAnswerShareByQuery(AnswerShareQuery query){
 		query.dealWith();
 		Integer result = answerShareMapper.countByQuery(query);
 		return result;
 	}
 	
 	/**
 	* 通过ids查询
 	*/
 	public List<AnswerShare> findAnswerShareByIds(List<Integer> ids){
 		List<AnswerShare> result = answerShareMapper.findByIds(ids);
		if(CollectionUtils.isNotEmpty(result)) {
			for (AnswerShare answerShare : result) {
				answerShare.dealWith();
			}
		}
		return result;
 	}
 	
}	